#!/usr/bin/env python
# -*- coding: utf-8 -*-

from tornado.web import RequestHandler
import pymongo
import re
import render
import codecs
from _base import BaseHandler
import datetime
import sys
sys.path.insert(0,'/home/leeray/workspaces/Python/wanalytics/')
sys.path.insert(0,'/opt/web/')
from Tools import getPid
from Tools import connectMySQL 
import json
from util import cache, settings
import _clientCache as clientcache
import logging


class UserLogin(BaseHandler):    
    def get(self):
        _uname = self.get_argument('uname', '').strip() or ''
        _pwd = self.get_argument('pwd','').strip() or ''
        
        resjson = UserCheck().check(_uname, _pwd)

        self.write(resjson)
        self.finish()


class UserCheck():
    def check(self, _uname, _pwd):
        #resjson = {"status": "failed", "code": 0}

        #if  _uname and _pwd:
        #    db = connectMySQL.connMySQL_stat()
        #    c=db.cursor()
        #    sql = 'select id, fid, type from stat_user where username="{0}" and password="{1}"'.format(_uname, _pwd)
        #    logging.info(sql)
        #    c.execute(sql)  
        #    res= c.fetchall()
        #    if res and res[0][0] > 0:
        #        resjson = {"status": "success","code": 1,"results": {"userid": res[0][1],"username": _uname, "type": res[0][2]}}
        #    
        #    c.close()
        #    db.close()
            
        resjson = {"status": "success","code": 1,"results": {"userid": 1,"username": _uname, "type": 1}}
        return resjson
